<?php
/**
 * Copyright (c) 2018,2345
 * 摘    要：删除程序
 * 作    者：林幸亿
 * 修改日期：2018.04.20
 */

require_once 'libraries/MysqlDbClass.php';
require_once 'libraries/RedisDbClass.php';

$id = null;
//Retrieve the User ID from the Query String URL
if (! empty($_GET['id']))
{
    $id = $_REQUEST['id'];
}

//Form submission and delete a user record
if (! empty($_POST))
{
    // keep track post values
    $id = $_POST['id'];

    $db = MysqlDb::getInstance();
    $sql = "DELETE FROM users WHERE id = " . $id;
    $count = $db->delete($sql);
    
    /*
    $redis = RedisDb::getInstance();
    //$result = $redis->del( 'user:' . $id);

    $test = $redis->hmget( 'user:' . $id, 'name');
    //die(var_dump($test));
    */
    //Redirect back to main page
    header("Location: index.php");
}
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link href="css/bootstrap.min.css" rel="stylesheet">
    </head>

    <body>
        <div class="container">

            <div class="span10 offset1">
                <div class="row">
                    <h3>删除用户 Delete a User</h3>
                </div>

                <form class="form-horizontal" action="delete.php" method="post">
                    <input type="hidden" name="id" value="<?php echo $id; ?>"/>
                    <p class="alert alert-error">您确定要删除吗？ Are you sure to delete ?</p>
                    <div class="form-actions">
                        <button type="submit" class="btn btn-danger">确认 Yes</button>
                        <a class="btn" href="index.php">取消 No</a>
                    </div>
                </form>
            </div>

        </div> <!-- /container -->
    </body>
</html>